package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CsBaseVo;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.detailCSBean;
import com.ymatou.iapi.godmch.parameter.mchCreateCsBean;
import com.ymatou.iapi.godmch.service.detailCSCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.cs_info;
import com.ymttest.database.model.godmch.buyer_invite_code;
import com.ymttest.database.model.godmch.buyer_invite_codeExample;
/**
*查看客服详情
*FreeMaker Template自动生成代码
*/
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.database.sqlwapper.godmch.buyer_invite_codeWapper;
@TestSuite
public class Ts_detailCS{
	private static detailCSBean detailcsBean;
	private static detailCSCall detailcsCall;
	DefGodMchWapper DefGodMchWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查看客服详情");
	}

	@Before
	public void caseUp() {
		detailcsBean=new detailCSBean();
		detailcsCall=new detailCSCall();
		DefGodMchWapper=new DefGodMchWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(detailcsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_detailCS_001() {
		Logger.start(true,"查看客服详情,验证商户id和客服id同时存在,并且关系匹配,返回成功");
		try {
			Integer templateId = 1;
			int mchId=GodmchManageCallService.CreateSellerMch();
			UserCreateBean usercreateBean = DGUserCallService.initCsUsercreateBean();
			int csId = DGUserCallService.UserCreateCall(usercreateBean);
			GodmchManageCallService.CreateCSCall(mchId, csId, templateId);
			GodmchManageCallService.EditCsRemark(mchId, csId, "remakr1");
			Logger.comment("创建渠道商客服:" + csId);
			detailcsBean.setCsId(csId);
			detailcsBean.setMchId(mchId);
			detailcsCall.setData(detailcsBean);
			detailcsCall.callService();			
			Logger.verifyEquals("200", detailcsCall.getString("status"), "验证status");
			CsBaseVo csb = detailcsCall.getResult();
			cs_info csi = DefGodMchWapper.selectCsInfo(csb.getMchId(), csb.getCsId()).get(0);
			Logger.verifyEquals(csb.getTemplateId(), csi.getTempldateId(), "验证TempldateId");
			Logger.verifyEquals(csb.getRemark(), csi.getRemark(), "验证Remark");
			String title = DefGodMchWapper.selectCsroleByMchId(0).stream().filter(csr -> csr.getRoleId().equals(csb.getTemplateId())).findFirst().get().getTitle();
			Logger.verifyEquals(csb.getTemplateTitle(), title, "验证title");
			//新增20191206
			Logger.verifyEquals(csb.getSetPwd(), false, "验证setPwd");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_detailCS_001_1() {
		Logger.start(true,"查看客服详情,商户主动添加客服验证商户id和客服id同时存在,并且关系匹配,返回成功");
		try {
//			Integer templateId = 1;
//			int mchId=GodmchManageCallService.CreateSellerMch();
//			UserCreateBean usercreateBean = DGUserCallService.initCsUsercreateBean();
//			int csId = DGUserCallService.UserCreateCall(usercreateBean);
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi2=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			Integer mchId=mchCreateCsBean.getMchId();
			Integer csId=csi2.getCsId();
			
			GodmchManageCallService.CreateCSCall(mchId, csId, mchCreateCsBean.getTemplateId());
			GodmchManageCallService.EditCsRemark(mchId, csId, "remakr1");
			Logger.comment("创建渠道商客服:" + csId);
			detailcsBean.setCsId(csId);
			detailcsBean.setMchId(mchId);
			detailcsCall.setData(detailcsBean);
			detailcsCall.callService();			
			Logger.verifyEquals("200", detailcsCall.getString("status"), "验证status");
			CsBaseVo csb = detailcsCall.getResult();
			cs_info csi = DefGodMchWapper.selectCsInfo(csb.getMchId(), csb.getCsId()).get(0);
			Logger.verifyEquals(csb.getTemplateId(), csi.getTempldateId(), "验证TempldateId");
			Logger.verifyEquals(csb.getRemark(), csi.getRemark(), "验证Remark");
			String title = DefGodMchWapper.selectCsroleByMchId(0).stream().filter(csr -> csr.getRoleId().equals(csb.getTemplateId())).findFirst().get().getTitle();
			Logger.verifyEquals(csb.getTemplateTitle(), title, "验证title");
			//新增20191206
			Logger.verifyEquals(csb.getSetPwd(), true, "验证setPwd");
			Logger.verifyEquals(csb.getTitle(), mchCreateCsBean.getTitle(), "验证title");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_detailCS_002() {
		Logger.start(true,"查看客服详情,验证商户id和客服id同时存在,但是关系不匹配-客服id不是当前商户下,返回失败");
		try {
			Integer templateId = 1;
			int mchId=GodmchManageCallService.CreateSellerMch();
			int mchId2=GodmchManageCallService.CreateSellerMch();
			UserCreateBean usercreateBean = DGUserCallService.initCsUsercreateBean();
			int csId = DGUserCallService.UserCreateCall(usercreateBean);
			GodmchManageCallService.CreateCSCall(mchId, csId, templateId);
			GodmchManageCallService.EditCsRemark(mchId, csId, "remakr1");
			Logger.comment("创建渠道商客服:" + csId);
			
			detailcsBean.setCsId(csId);
			detailcsBean.setMchId(mchId2);
			detailcsCall.setData(detailcsBean);
			detailcsCall.callService();			
			Logger.verifyEquals("200", detailcsCall.getString("status"), "验证status");
			Logger.verifyIsNull(detailcsCall.getResult(), "验证不会查出结果");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_detailCS_003() {
		Logger.start(true,"查看客服详情,验证商户id不存在,返回失败");
		try {
			int mchId=GodmchManageCallService.CreateSellerMch();
			UserCreateBean usercreateBean = DGUserCallService.initCsUsercreateBean();
			int csId = DGUserCallService.UserCreateCall(usercreateBean);
			GodmchManageCallService.CreateCSCall(mchId, csId, 1);
			detailcsBean.setCsId(csId);
			detailcsBean.setMchId(-1);
			detailcsCall.setData(detailcsBean);
			detailcsCall.callService();			
			Logger.verifyEquals("200", detailcsCall.getString("status"), "验证status");
			Logger.verifyIsNull(detailcsCall.getResult(), "验证不会查出结果");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_detailCS_004() {
		Logger.start(true,"查看客服详情,验证客服id不存在,返回失败");
		try {
			int mchId=GodmchManageCallService.CreateSellerMch();
			detailcsBean.setMchId(mchId);
			detailcsBean.setCsId(1);
			detailcsCall.setData(detailcsBean);
			detailcsCall.callService();			
			Logger.verifyEquals("200", detailcsCall.getString("status"), "验证status");
			Logger.verifyIsNull(detailcsCall.getResult(), "验证不会查出结果");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_detailCS_005() {
		Logger.start(true,"查看客服详情,验证商户id为空,返回失败");
		try {
			detailcsBean.setCsId(1);
			detailcsCall.setData(detailcsBean);
			detailcsCall.callService();			
			Logger.verifyEquals("4001", detailcsCall.getString("status"), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_detailCS_006() {
		Logger.start(true,"查看客服详情,验证客服id为空,返回失败");
		try {
			detailcsBean.setMchId(1);
			detailcsCall.setData(detailcsBean);
			detailcsCall.callService();			
			Logger.verifyEquals("4001", detailcsCall.getString("status"), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_detailCS_007() {
		Logger.start(true,"查看客服详情,验证邀请制客服,返回成功(新增20200610)");
		try {
			Integer templateId = 1;
			int mchId=GodmchManageCallService.CreateSellerMch();
			UserCreateBean usercreateBean = DGUserCallService.initCsUsercreateBean();
			int csId = DGUserCallService.UserCreateCall(usercreateBean);
			
			//设置商户是邀请制 新增 2020610
		    GodMemberService.setCollectionMobile(mchId, true);
            GodMemberService.setInvitationCodeCall(mchId, true, 0);
            
			GodmchManageCallService.CreateCSCall(mchId, csId, templateId);
			GodmchManageCallService.EditCsRemark(mchId, csId, "remakr1");
			Logger.comment("创建渠道商客服:" + csId);
            
			detailcsBean.setCsId(csId);
			detailcsBean.setMchId(mchId);
			detailcsCall.setData(detailcsBean);
			detailcsCall.callService();			
			Logger.verifyEquals("200", detailcsCall.getString("status"), "验证status");
			CsBaseVo csb = detailcsCall.getResult();
			cs_info csi = DefGodMchWapper.selectCsInfo(csb.getMchId(), csb.getCsId()).get(0);
			Logger.verifyEquals(csb.getTemplateId(), csi.getTempldateId(), "验证TempldateId");
			Logger.verifyEquals(csb.getRemark(), csi.getRemark(), "验证Remark");
			String title = DefGodMchWapper.selectCsroleByMchId(0).stream().filter(csr -> csr.getRoleId().equals(csb.getTemplateId())).findFirst().get().getTitle();
			Logger.verifyEquals(csb.getTemplateTitle(), title, "验证title");
			//新增20191206
			Logger.verifyEquals(csb.getSetPwd(), false, "验证setPwd");
			//新增邀请码
			buyer_invite_codeExample example=new buyer_invite_codeExample();
			buyer_invite_codeWapper codeMapper=new buyer_invite_codeWapper();
			example.createCriteria().andUserIdEqualTo(csId);
			buyer_invite_code code=codeMapper.selectByExample(example).get(0);	
			Logger.verifyEquals(csb.getInviteCode(), code.getInviteCode(), "验证inviteCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}